package com.example.hasee.showinfo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

import com.example.hasee.data.entity.School;
import com.example.hasee.libraryreservation.R;

import java.util.List;

public class ShowInfoFragment extends Fragment implements ShowInfoContract.View{
    private ListView lvSchool;
    private ShowInfoContract.Presenter mPresenter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_show_info, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        lvSchool=view.findViewById(R.id.lvSchool);
        mPresenter=new ShowInfoPresenter(this);
        mPresenter.getInfo();
    }

    @Override
    public void showSchoolList(List<School> info) {
        final SchoolAdapter adapter=new SchoolAdapter(getContext(),info);
        lvSchool.setAdapter(adapter);
    }

    @Override
    public void showError(String message) {
        Toast.makeText(getContext(),message,Toast.LENGTH_SHORT).show();
    }
}
